package test.com.sms.selenium.singlepoint.util.helper;

import java.util.Set;

import org.openqa.selenium.By;

import test.com.sms.selenium.singlepoint.util.SpSearchPageUtil;
import test.com.sms.selenium.singlepoint.util.SpIncidentEditPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

/** help to do search page related tests */
public class SpTicketSearchPageTestHelper {
	
	/** 
	 * start from Search Page, after input a incident No. and search, 
	 * goto Ticket Edit Page to edit the incident.*/
	public static void openRecordByIncidentNo(String incidentNo){
		
		SpSearchPageUtil.searchByIncidentId(incidentNo);
		
		// assert at least one record
		SeleniumUtil.assertTrue("Search result list should show.", SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpSearchPageUtil.SEARCH_TBL_RESULT)));
		SpSearchPageUtil.waitForResultListToLoadComplete();
		SeleniumUtil.assertTrue("There should be at least one result.", SeleniumUtil.findElements(SeleniumUtil.getCachedElement(SpSearchPageUtil.SEARCH_TBL_RESULT), By.xpath(".//a")).size() > 0);
		
		// click on the first result list record
		Set<String> before = SeleniumUtil.getWindowHandles();
		SeleniumUtil.click(SeleniumUtil.findElement(SeleniumUtil.getCachedElement(SpSearchPageUtil.SEARCH_TBL_RESULT), By.xpath(".//a")));
		SeleniumUtil.switchToPromptedWindowAfterWait(before, 500);
		
		// go to event tab
		SpIncidentEditPageUtil.waitForEditPageToLoad();
	}
}
